package com.csii.activiti.server.core.job;

import com.csii.activiti.server.core.entity.db.ActFlowCallbackEntity;
import com.csii.activiti.server.core.service.FlowCallbackManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.List;

public class FlowCallbackJob {
    @Autowired
    private FlowCallbackManagementService flowCallbackManagementService;

    @Value("${activity.callback.retriesCount:5}")
    private int retriesCount;

    @Scheduled(cron = "${activity.callback.jobCron:0/30 * * * * ? }")
    public void execution(){
        List<ActFlowCallbackEntity> callbackList = flowCallbackManagementService.queryCallbackEntityLtRetriesCount(retriesCount);
        for (ActFlowCallbackEntity callback : callbackList) {
            flowCallbackManagementService.reCallbackById(callback.getId());
        }

    }
}
